/**
 * @author Aaron
 * @createTime 17:57 2022/5/26
 **/
package db_main

import (
	"fmt"
	"gorm.io/gorm"
	"longmen/server/pkg/common/api_models"
	"longmen/server/pkg/common/helper/util"
	"longmen/server/pkg/db/mysql"
	"longmen/server/pkg/db/mysql/models/models_main"
)

func GetPropsParam(param map[string]interface{}, order string) ([]*api_models.Props, error) {
	fName := "GetPropsParam"
	o := make([]*api_models.Props, 0)
	table := mysql.GetRTable(&models_main.Props{})
	mysql.Condition(table, param, "", order, 0, 0)
	err := table.Find(&o).Error
	if err != nil {
		err = fmt.Errorf("%s%s", util.Convert(fName), err.Error())
	}
	return o, err
}

func GetPropsINFO(id int) (*models_main.Props, error) {
	var props *models_main.Props
	err := mysql.GetRTable(&models_main.Props{}).Where("id=?", id).Find(&props).Error

	if err != nil {
		return nil, err
	}
	return props, nil
}

func InsertProps(tx *gorm.DB, prop *models_main.Props) error {
	fName := "InsertProps"
	err := tx.Create(prop).Error
	if err != nil {
		err = fmt.Errorf("%s%s", util.Convert(fName), err.Error())
	}
	return err
}
